﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WF.VecDraw.Dialog.Controls
{
    public delegate void LayerFocusChangedEventHandler(object sender, LayerFocusChangedEventArgs e);

    /// <summary>
    /// Interaction logic for LayerDisplay.xaml
    /// </summary>
    public partial class LayerDisplay : UserControl
    {
        public event LayerFocusChangedEventHandler LayerGetFocus;

        Gencode.VECore.CanvasLayer _layer;
        
        bool _selected = false;
        public bool Selected
        {
            get
            {
                return _selected;
            }
            set
            {
                _selected = value;

                if (_selected)
                    this.Background = Brushes.LightBlue;
                else
                    this.Background = Brushes.AliceBlue;

                if (_selected && LayerGetFocus != null)
                    LayerGetFocus(this, new LayerFocusChangedEventArgs(_selected, _layer));
            }
        }

        public LayerDisplay(Gencode.VECore.CanvasLayer layer)
        {
            InitializeComponent();
            
            _layer = layer;
            Selected = true;
        }

        private void MouseLeftUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (!Selected)
            {
                Selected = true;
            }
        }
    }

    public class LayerFocusChangedEventArgs : EventArgs
    {
        public LayerFocusChangedEventArgs(bool selected, Gencode.VECore.CanvasLayer layer)
        {
            _selected = selected;
            _layer = layer;
        }

        bool _selected;
        public bool Selected
        {
            get
            {
                return _selected;
            }
        }

        Gencode.VECore.CanvasLayer _layer;
        public Gencode.VECore.CanvasLayer Layer
        {
            get
            {
                return _layer;
            }
        }
    }
}
